package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.applySupplierBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.editmchBean;
import com.ymatou.iapi.godmch.parameter.mchInfo;
import com.ymatou.iapi.godmch.parameter.parentInfo;
import com.ymatou.iapi.godmch.parameter.registerByCodeBean;
import com.ymatou.iapi.godmch.parameter.setShareTypeBean;
import com.ymatou.iapi.godmch.parameter.simplemchBean;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.applySupplierCall;
import com.ymatou.iapi.godmch.service.createCSCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.getAgentPromotePicCall;
import com.ymatou.iapi.godmch.service.registerByCodeCall;
import com.ymatou.iapi.godmch.service.setShareTypeCall;
import com.ymatou.iapi.godmch.service.simplemchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.model.country_info;
import com.ymttest.database.model.cs_info;
import com.ymttest.database.model.cs_infoKey;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.model.mch_relation;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.cs_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_relationWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取商户信息(头像,名称,微信号)
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_simplemch{
	private static simplemchBean bean;
	private static simplemchCall call;
	private static mch_infoWapper mchinfoWapper=new mch_infoWapper();
	private static country_infoWapper countryinfoWapper=new country_infoWapper();
	
	private  setShareTypeBean shareTypeBbean=new setShareTypeBean();
	private  setShareTypeCall shareTypeCall=new setShareTypeCall();
	
	Integer agent_promote_mchId=Integer.parseInt(EnvSetup.getData("agent_promote_mchId"));
	Integer sale_distribution=Integer.parseInt(EnvSetup.getData("sale_distribution"));
	Integer masterChainShopId_wechatDirectPayMode=Integer.parseInt(EnvSetup.getData("masterChainShopId_wechatDirectPayMode"));
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商户信息(头像,名称,微信号)");
	}

	@Before
	public void caseUp() {
		bean=new simplemchBean();
		call=new simplemchCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_001() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是代理商(不可以发展下线),返回成功");
		try {
			//渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			//代理
			usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			List<createmchBean> createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl, userId_agent);
			createmchList.get(0).setCountry("CHN");//设为国内，变为纯代理商
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[createmchList.size()]));
            
            bean.setMchId(userId_agent);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(userId_agent,7);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_002() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是代理商(可以发展下线),返回成功");
		try {
			//渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			//代理
			usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			//设为Vip渠道
			GodmchManageCallService.SetVip(createmchbean.getMchId());
			
			List<createmchBean> createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl, userId_agent);
			createmchList.get(0).setCountry("CHN");//设为国内，变为纯代理商
			//createmchList.get(0).setCountry("HKD");//设为国内，变为纯代理商
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[createmchList.size()]));
            
            bean.setMchId(userId_agent);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(userId_agent,1);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_003() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是渠道商,返回成功");
		try {
			//新增渠道商
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel();
			createmchbean.setCountry("HKG");
			GodmchManageCallService.createmchCallForChannel(createmchbean);
            int mchId=createmchbean.getMchId();
            
            bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(mchId,2);	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_004() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是 代理+渠道,返回成功");
		try {
			//渠道
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			//代理
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			List<createmchBean> createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl, userId_agent);
			createmchList.get(0).setCountry("USA");
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[createmchList.size()]));

            bean.setMchId(userId_agent);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(userId_agent,3);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_005() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是 渠道 的客服,返回成功");
		try {
			//渠道
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			
			usercreateBean=DGUserCallService.initUsercreateBean();
			int csId=DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			
			GodmchManageCallService.CreateCSCall(userId_channl,csId,4);
			
            bean.setMchId(csId);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(userId_channl,5);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_006() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是 纯代理 的客服,返回成功");
		try {
			//渠道
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			//代理
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean);
			
			usercreateBean=DGUserCallService.initUsercreateBean();
			int csId=DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			List<createmchBean> createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl, userId_agent);
			createmchList.get(0).setCountry("CHN");
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[createmchList.size()]));
			
			GodmchManageCallService.CreateCSCall(userId_agent,csId,4);
			
            bean.setMchId(csId);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(userId_agent,4);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_007() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是 代理+渠道 的客服,返回成功");
		try {
			//渠道
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			//代理
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean);
			
			usercreateBean=DGUserCallService.initUsercreateBean();
			int csId=DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			List<createmchBean> createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl, userId_agent);
			createmchList.get(0).setCountry("USA");
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[createmchList.size()]));
			
			createCSCall csCall=GodmchManageCallService.CreateCSCall(userId_agent,csId,4);
			
            bean.setMchId(csId);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(userId_agent,6);		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_008() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户id为空,返回失败,提示错误");
		try {
			
	        bean.setMchId(null);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("4001", call.getStatus1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("商户id不能为空"), "验证Message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_009() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户分享类型,返回成功");
		try {
			//新增渠道商
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel();
			createmchbean.setCountry("HKG");
			GodmchManageCallService.createmchCallForChannel(createmchbean);
            int mchId=createmchbean.getMchId();
            
           //切换分享类型
            for(int i=1;i<=4;i++){
				shareTypeBbean.setMchId(mchId);
				shareTypeBbean.setMchShareType(i);//独立h5
				shareTypeBbean.setMchStatus(0);
				shareTypeBbean.setRemark("切换分享类型");
				shareTypeCall.setData(shareTypeBbean);
				shareTypeCall.callService();
				
	            bean.setMchId(mchId);
				call.setData(bean);
				call.callService();	
				//验证
				checkVerify(mchId,2);	
            }
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_010() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证是双店模式,返回成功");
		try {
			//新增渠道商
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
            int mchId=createmchbean.getMchId();
            //设置双店模式
    		setShareTypeBean setBean=GodmchManageCallService.initsetShareTypeV2(mchId);
			GodmchManageCallService.setShareTypeV2Call(setBean);
			
            bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(mchId,2);	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_011() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是渠道商-设置买家客服(20200319新增),返回成功");
		try {
			//渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
            
			GodmchManageCallService.setBuyerCs(userId_channl);
			
            bean.setMchId(userId_channl);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(userId_channl,2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_012() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证独立商户主体,返回成功");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
            
            bean.setMchId(createCall.getmchId());
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(createCall.getmchId(),2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_013() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证独立商户代理,返回成功");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			applyAgentCall applyAgentCall=GodmchManageCallService.applyAndapproveAgent(createCall.getmchId());
            
            bean.setMchId(applyAgentCall.getAgentId());
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(applyAgentCall.getAgentId(),3);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_014() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证独立商户供货商,返回成功");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			//申请供货商
			applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createCall.getmchId());
			applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
			//审核供货商
			GodmchManageCallService.approveSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            
            bean.setMchId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(applySupplierCall.getSupplierId(),2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_015() {
		Logger.start(true,"商户信息,验证商户id存在,微信HipoPay支付通道 payMode=0：不支持HipoPay");
		try {
			String title="title1";
			String wc="wc2";
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			GodmchManageCallService.editMchInfo(ccbean.getMchId(),title, DGUserCallService.DefImg2,wc);
			
			//公共小程序切换 成独立小程序
			shareTypeBbean=GodmchManageCallService.initsetShareTypeV2(ccbean.getMchId());
			shareTypeBbean.setMchId(ccbean.getMchId());
			shareTypeBbean.setPayMode(0);//不支持HipoPay
			shareTypeCall.setData(shareTypeBbean);
			shareTypeCall.callService();
			
			bean.setMchId(ccbean.getMchId()); 
			call.setData(bean);
			call.callService();	
			
			checkVerify(ccbean.getMchId(),2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch022() {
		Logger.start(true,"商户信息,验证商户id存在,微信国内支付通道 domesticPayMode=0：不支持 微信国内支付通道");
		try {
			String title="title1";
			String wc="wc2";
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			GodmchManageCallService.editMchInfo(ccbean.getMchId(),title, DGUserCallService.DefImg2,wc);
			
			//公共小程序切换 成独立小程序
			shareTypeBbean=GodmchManageCallService.initsetShareTypeV2(ccbean.getMchId());
			shareTypeBbean.setMchId(ccbean.getMchId());
			shareTypeBbean.setDomesticPayMode(0);//不支持微信国内支付
			shareTypeCall.setData(shareTypeBbean);
			shareTypeCall.callService();
			
			bean.setMchId(ccbean.getMchId()); 
			call.setData(bean);
			call.callService();		
			
			checkVerify(ccbean.getMchId(),2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch023() {
		Logger.start(true,"商户信息,验证商户id存在,微信国内支付通道 domesticPayMode=1：盛付通");
		try {
			String title="title1";
			String wc="wc2";
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			GodmchManageCallService.editMchInfo(ccbean.getMchId(),title, DGUserCallService.DefImg2,wc);
			
			//公共小程序切换 成独立小程序
			shareTypeBbean=GodmchManageCallService.initsetShareTypeV2(ccbean.getMchId());
			shareTypeBbean.setMchId(ccbean.getMchId());
			shareTypeBbean.setDomesticPayMode(1);//盛付通
			shareTypeCall.setData(shareTypeBbean);
			shareTypeCall.callService();
			
			bean.setMchId(ccbean.getMchId()); 
			call.setData(bean);
			call.callService();		
			
			checkVerify(ccbean.getMchId(),2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch024() {
		Logger.start(true,"商户信息,验证商户id存在,可以发布境内商品 pulishDomestic=true");
		try {
			String title="title1";
			String wc="wc2";
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			GodmchManageCallService.editMchInfo(ccbean.getMchId(),title, DGUserCallService.DefImg2,wc);
			
			//公共小程序切换 成独立小程序
			shareTypeBbean=GodmchManageCallService.initsetShareTypeV2(ccbean.getMchId());
			shareTypeBbean.setMchId(ccbean.getMchId());
			shareTypeBbean.setPulishDomestic(true);//可以发布境内商品
			shareTypeCall.setData(shareTypeBbean);
			shareTypeCall.callService();
			
			bean.setMchId(ccbean.getMchId()); 
			call.setData(bean);
			call.callService();		
			
			checkVerify(ccbean.getMchId(),2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch025() {
		Logger.start(true,"商户信息,验证商户id存在,不可以发布境内商品 pulishDomestic=false");
		try {
			String title="title1";
			String wc="wc2";
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			GodmchManageCallService.editMchInfo(ccbean.getMchId(),title, DGUserCallService.DefImg2,wc);
			
			//公共小程序切换 成独立小程序
			shareTypeBbean=GodmchManageCallService.initsetShareTypeV2(ccbean.getMchId());
			shareTypeBbean.setMchId(ccbean.getMchId());
			shareTypeBbean.setPulishDomestic(false);//不可以发布境内商品
			shareTypeCall.setData(shareTypeBbean);
			shareTypeCall.callService();
			
			bean.setMchId(ccbean.getMchId()); 
			call.setData(bean);
			call.callService();		
			
			checkVerify(ccbean.getMchId(),2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_026() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是为独立云特卖分销版商户,返回成功");
		try {
//			//渠道
//			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
//			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
//			//代理
//			usercreateBean1=DGUserCallService.initUsercreateBean();
//			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean1);
//			
//			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
//			GodmchManageCallService.createmchCallForChannel(createmchbean);
//			List<createmchBean> createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl, userId_agent);
//			createmchList.get(0).setCountry("CHN");//设为国内，变为纯代理商
//			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
//					createmchBean[createmchList.size()]));
            Integer mchId=sale_distribution;
//            String code= GodmchManageCallService.getInviteDistributorOrganizationPic(mchId).getInviteCode();
//            registerByCodeBean registerBean= GodmchManageCallService.initRegisterByCode(mchId, code);
//            registerByCodeCall registerCall=GodmchManageCallService.registerByCodeCall(registerBean);
            bean.setMchId(mchId);
			call.setData(bean);
			call.callService();	
			//验证
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			mchInfo return_info=call.getMchInfo();
			Logger.verifyEquals(return_info.getSaleDistribution(), true, "验证数据库mch_info中的saleDistribution与返回的是否一致");
			Logger.verifyEquals(return_info.getAgentPromote(), false, "验证数据库mch_info中的agentPromote与返回的是否一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_027() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是为代理裂变的代理商,返回成功");
		try {

            Integer mchId=agent_promote_mchId;
            //获取主商户agentType
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			
			//申请 审核代理1
			applyAgentCall applyAgent =GodmchManageCallService.applyAndapproveAgent(mchId);
			editmchBean editmchBean=GodmchManageCallService.IniteditmachBean(applyAgent.getAgentId());
            GodmchManageCallService.editmachCall(editmchBean);
			
			getAgentPromotePicCall getAgentPromotePicCall=GodmchManageCallService.getAgentPromotePic(applyAgent.getAgentId());
			Thread.sleep(5000);
			registerByCodeBean registerBean=GodmchManageCallService.initRegisterByCode(mchId, getAgentPromotePicCall.getInviteCode());
			registerByCodeCall registerCall=GodmchManageCallService.registerByCodeCall(registerBean);
			Integer agentId2=registerCall.getRegMchId();
			Logger.comment("################ agentId2:"+agentId2);
            bean.setMchId(agentId2);
			call.setData(bean);
			call.callService();	
			//验证
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			mchInfo return_info=call.getMchInfo();
			Logger.verifyEquals(return_info.getSaleDistribution(), false, "验证数据库mch_info中的saleDistribution与返回的是否一致");
			Logger.verifyEquals(return_info.getAgentPromote(), true, "验证数据库mch_info中的agentPromote与返回的是否一致");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_simplemch_0028() {
		Logger.start(true,"获取商户信息(头像,名称,微信号),验证商户是代理商(不可以发展下线),返回成功");
		try {
//			//渠道
//			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
//			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
//			//代理
//			usercreateBean1=DGUserCallService.initUsercreateBean();
//			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean1);
//			
//			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
//			GodmchManageCallService.createmchCallForChannel(createmchbean);
//			List<createmchBean> createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl, userId_agent);
//			createmchList.get(0).setCountry("CHN");//设为国内，变为纯代理商
//			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
//					createmchBean[createmchList.size()]));
            
            bean.setMchId(masterChainShopId_wechatDirectPayMode);
			call.setData(bean);
			call.callService();	
			//验证
			checkVerify(bean.getMchId(),2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	/**
	 * 断言
	 * @param mchId 商户ID
	 * @param Role  商户角色
	 *  1：代理商
		2：渠道商
		3：代理商 + 渠道商
		4：代理商客服
		5：渠道商客服
		6：代理商 + 渠道商客服
		7：代理商（不可招下级代理）
	 * @throws InterruptedException
	 */
	private void checkVerify(int mchId, int role) throws InterruptedException
	{
		//数据库验证
		Logger.verifyEquals("200", call.getStatus1(), "验证status");
		Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
		mchInfo return_info=call.getMchInfo();
		
		HashMap<String,Object> map=new HashMap();
		map.put("mchId", mchId);
		mch_info p_mch= mchinfoWapper.selectby(map).get(0);
		
	    Logger.verifyEquals(return_info.getMchTitle(), p_mch.getMchTitle(), "验证数据库mch_info中的MchTitle与返回的是否一致");
	    Logger.verifyEquals(return_info.getAvatar(), p_mch.getAvatar(), "验证数据库mch_info中的Avatar与返回的是否一致");
	    Logger.verifyEquals(return_info.getWechat(), p_mch.getWechat(), "验证数据库mch_info中的Wechat与返回的是否一致");
	    Logger.verifyEquals(return_info.getVip(), p_mch.getVip()==0?false:true, "验证数据库mch_info中的Vip与返回的是否一致");

		/**
		 * 请求的商户id对应角色 Role
		1：代理商
		2：渠道商
		3：代理商 + 渠道商
		4：代理商客服
		5：渠道商客服
		6：代理商 + 渠道商客服
		7：代理商（不可招下级代理）
		 */
	    Logger.verifyEquals(return_info.getRole(), role, "验证数据库mch_info中的Role与返回的是否一致");
	    //商户Id mchId
	    if(role!=4 && role!=5)
	    {
	       Logger.verifyEquals(return_info.getMchId(), p_mch.getMchId(), "验证数据库mch_info中的MchId与返回的是否一致");
	    }
	    else//商户id（角色为客服，返回其对应商户id）
	    {
			cs_infoKey k=new cs_infoKey();
			k.setCsId(bean.getMchId());
			cs_infoWapper csWapper=new cs_infoWapper();
			cs_info info=csWapper.selectBycsId(k);
	    	Logger.verifyEquals(info.getMchId(), p_mch.getMchId(), "验证客户其对应商户id与返回的是否一致");
	    	//Logger.verifyEquals(return_info.getCountry(), p_mch.getCountry(), "验证客户其对应商户Country与返回的是否一致");
	    }
	    //20191010新增
	    Logger.verifyEquals(return_info.getCountry(), p_mch.getCountry(), "验证数据库mch_info中的Country与返回的是否一致");
	    //结算币种返回字段
	    country_info countryinfo=countryinfoWapper.selectByPrimaryKey(p_mch.getCountry());
	    Logger.verifyEquals(countryinfo.getCurrency(), return_info.getCurrency(), "验证商户币种");
	    
	    Logger.verifyEquals(return_info.getMchShareType(), p_mch.getMchShareType(), "验证商户分享类型");
	    if(role==2 || role==5)
	    {
	    	Logger.comment("###### 1 #######"+role);
	    	Logger.verifyEquals(0,return_info.getAgentModel(), "验证非代理商和渠道商的客服场景 商户代理模式");
	    }
	    else {
	    	Logger.comment("###### 2 #######"+role);
	    	//关系表
	    	// mch_relation
	    	Map<String, Object> map2 = new HashMap();
			map2.put("mchId", return_info.getMchId());
	    	mch_relation mchrelation = new mch_relationWapper().selectby(map2).get(0);
	    	Logger.verifyEquals(mchrelation.getAgentModel(),return_info.getAgentModel(), "验证代理商和代理商客服场景 商户代理模式");
		}
	    
		Logger.verifyEquals(return_info.getPayMode(),p_mch.getPayMode(), "验证PayMode");
		//支付宝支付方式 新增20191224
		Logger.verifyEquals(return_info.getAliPayMode(),p_mch.getAliPayMode(), "验证AliPayMode");
		
		//dualMode 双店模式 0：正常模式 1：双店模式
		Logger.verifyEquals(return_info.getDualMode(),p_mch.getDualMode(), "验证DualMode");
		//买家端购买 新增20200319
		Logger.verifyEquals(return_info.getBuyerCsEnabled(),p_mch.getBuyerCsEnabled(), "验证BuyerCsEnabled");
		Logger.verifyEquals(return_info.getBuyerCsWechat(),p_mch.getBuyerCsWechat(), "验证BuyerCsWechat");
		
		//是否独立商户主账号 20200326
		Logger.verifyEquals(p_mch.getIndepMchFlg()==1?true:false, return_info.getIndepMchSelf(), "验证是否独立商户主账号 indepMchSelf");
	    //新增 20200407
		Logger.verifyEquals(p_mch.getSettlementCurrency(),return_info.getSettlementCurrency(), "验证SettlementCurrency");
		Logger.verifyEquals(p_mch.getPayMode(),return_info.getPayMode(), "验证PayMode");
		Logger.verifyEquals(p_mch.getDomesticPayMode(),return_info.getDomesticPayMode(), "验证DomesticPayMode");
		Logger.verifyEquals(p_mch.getPulishDomestic()==0?false:true,return_info.getPulishDomestic(), "验证PulishDomestic");
		
	    //20201027 新增字段  masterChainShopId连锁店、wechatDirectPayMode微信直连
		Logger.verifyEquals(p_mch.getWechatDirectPayMode(),return_info.getWechatDirectPayMode(), "验证WechatDirectPayMode");
	}
}